package top.buyibuyi.course.dao;

import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import top.buyibuyi.course.pojo.ChooseCourse;
import top.buyibuyi.course.pojo.Course;

import java.util.List;

@Mapper
public interface SelectChooseDao {

    @Select("<script>"
            + "select * from choosecourse where 1=1 "
            +"<if test=\"cname != null and cname != ''\">"
            +" and cname LIKE concat('%', #{cname}, '%')"
            +"</if>"
            +"<if test=\"aname != null and aname != ''\">"
            +" and aname LIKE concat('%', #{aname}, '%')"
            +"</if>"
            +"and id limit #{startPage},#{limit}"
            +"</script>")
    List<ChooseCourse> selectChooseCourse(@Param("startPage") int startPage, @Param("limit") int limit, @Param("cname") String cname,@Param("aname") String aname);

    @Select("<script>"
            + "select count(*) as 'totalpage' from choosecourse where 1=1 "
            +"<if test=\"cname != null and cname != ''\">"
            +" and cname LIKE concat('%', #{cname}, '%')"
            +"</if>"
            +"<if test=\"aname != null and aname != ''\">"
            +" and aname LIKE concat('%', #{aname}, '%')"
            +"</if>"
            +"</script>")
    int selectCount(ChooseCourse choose);

    @Results({
            @Result(column = "courseid",property = "courseid"),
            @Result(column = "courseid",property = "course", one = @One(select = "top.buyibuyi.course.dao.SelectCourseDao.selectCourseById",fetchType = FetchType.LAZY))
    })
    @Select("select * from choosecourse where id = #{id}")
    ChooseCourse selectChooseCourseById(int id);

    @Select("select id from choosecourse where week = #{week} and sectionnum = #{sectionnum} and classroomn = #{classroomn}")
    ChooseCourse selectByThree(ChooseCourse chooseCourse);
}
